<?php
require( __DIR__ . '/inc/common.php' );

// Get the video id from URL.
// Such as "UCHDm-DKoMyJxKVgwGmuTaQA"
$channel_id = @$_GET['id'];
$page = ( isset( $_GET['page'] ) && is_numeric( $_GET['page'] ) ) ? intval( $_GET['page'] ) : 1;

$templates = new League\Plates\Engine( 'themes/' . $config['theme'] );

if ( strlen( $channel_id ) == 24 ) {
	$channel = new \Vioscope\Channel( $channel_id, $page );
	echo $templates->render( 'channel', array(
		'info' => array_merge( $channel->info, array(
			'page' => $page,
			'next_page_url' => $channel->get_change_page_url(true),
			'previous_page_url' => $channel->get_change_page_url(false),
		) ),
		'config' => $config,
	) );
} else {
	echo $templates->render( 'channel', array(
		'error' => 'No valid channel id provided'
	) );
}
